#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N], cnt[N], sum[N];
void solve() {
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  sort(a + 1, a + n + 1);
  int A = a[n];
  rep(i, 1, n) cnt[a[i]]++;
  rep(i, 1, A) sum[i] = sum[i - 1] + cnt[i];
  ll ans = n + 1ll * (cnt[1] - n) * m;
  rep(x, 2, A) {
    ll now = -1ll * n * m;
    rep(p, 1, (A + x - 1) / x) {
      int l = (p - 1) * x, r = min(A, p * x);
      int y = sum[r] - sum[l];
      now += 1ll * p * y;
      now += 1ll * min(cnt[p], y) * m;
    }
    ans = max(ans, now);
  }
  rep(i, 1, n) cnt[a[i]]--;
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}